#include <KEY_BOARD_4X4.h>

#if KEYBOARD_EN
void scan_wait()
{
}

key_board_4x4_value get_key_board()
{
	uint8_t tmp;
	tmp = KEY_GPIO;
	KEY_GPIO = 0XF0;
	scan_wait();
	tmp = tmp | KEY_GPIO;
	KEY_GPIO = 0X0F;

#if KEY_BOARD_ROW_USE_MSB_OR_LSB
	tmp = (tmp << 4) | (tmp >> 4);
#endif

#if KEY_BOARD_ROW_IS_L_TO_H
	tmp = (tmp & 0xf6) | ((tmp & 0x01) << 3) | ((tmp & 0x08) >> 3);
	tmp = (tmp & 0xf9) | ((tmp & 0x02) << 1) | ((tmp & 0x04) >> 1);
#endif

#if KEY_BOARD_LINE_IS_L_TO_H
	tmp = (tmp & 0x6f) | ((tmp & 0x10) << 3) | ((tmp & 0x80) >> 3);
	tmp = (tmp & 0x9f) | ((tmp & 0x20) << 1) | ((tmp & 0x40) >> 1);
#endif

	switch (tmp)
	{
	case 0xee:
		return key_0_0;
		break;
	case 0xed:
		return key_0_1;
		break;
	case 0xeb:
		return key_0_2;
		break;
	case 0xe7:
		return key_0_3;
		break;
	case 0xde:
		return key_1_0;
		break;
	case 0xdd:
		return key_1_1;
		break;
	case 0xdb:
		return key_1_2;
		break;
	case 0xd7:
		return key_1_3;
		break;
	case 0xbe:
		return key_2_0;
		break;
	case 0xbd:
		return key_2_1;
		break;
	case 0xbb:
		return key_2_2;
		break;
	case 0xb7:
		return key_2_3;
		break;
	case 0x7e:
		return key_3_0;
		break;
	case 0x7d:
		return key_3_1;
		break;
	case 0x7b:
		return key_3_2;
		break;
	case 0x77:
		return key_3_3;
		break;
	default:
		return key_not_press;
		break;
	}
}
#endif
